#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#include <climits>
using namespace std;

int n, k, s, t, dp[10002];
vector<int> v[10001];
int main() 
{
    cin >> n >> k;
    while (k--) 
    {
        cin >> s >> t;
        v[s].push_back(t);
    }

    for (int i = n; i >= 0; --i) 
    {
        if (v[i].size() > 0)
        {
            for (int j = 0; j < v[i].size(); ++j)
            {
                dp[i] = max(dp[i], dp[i + v[i][j]]);
            }
        }   
        else
        {
            dp[i] = dp[i + 1] + 1;
        }
    }
    printf("%d", dp[1]);
}